//
//  OrderDetailViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/5/8.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "OrderTableViewCell.h"
#import "CancleVC.h"
#import "ShopDetailViewController.h"
#import "PayViewController.h"
#import "LogisticsViewController.h"
#import "SalesViewController.h"
#import "LYDetailsModel.h"
@interface OrderDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) NSMutableArray *orderArray;
@property(assign, nonatomic)  NSInteger timeCount;
@property(strong, nonatomic) NSTimer *timer;
@property(strong, nonatomic) LYDetailsModel *lyModel;
@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=MyString(@"订单详情");
    [self getDetaiData];
    [self.view addSubview:self.tableView];
    // Do any additional setup after loading the view.
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.backgroundColor=Gray_Color;
        _tableView.dataSource=self;
        _tableView.showsHorizontalScrollIndicator=NO;
        _tableView.separatorColor=SeparatorColor;
        [_tableView registerNib:[UINib nibWithNibName:@"OrderTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"OrderTableViewCell"];
    }
    return _tableView;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.lyModel.items.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if ([self.lyModel.status intValue]==0) {
        return 140;
    }else if ([self.lyModel.status intValue]==300){
        return 180;
    }
    return 130;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 185;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    itemsModel *model=self.lyModel.items[indexPath.row];
    OrderTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"OrderTableViewCell"];
    [cell.shopImg sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    cell.shopName.text=model.spuName;
    cell.shopDetail.text=[NSString stringWithFormat:@"工艺类型:%@",model.saleName];
    cell.shopPrice.text=[NSString stringWithFormat:@"¥ %@.00",model.price];
    cell.shopNumber.text=[NSString stringWithFormat:@"x %@",model.quantity];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSString *s=MyString(@"等待付款");
    CGSize size=[s sizeWithAttributes:@{NSFontAttributeName:FontAndStyle14 }];
    UIView *view=[[UIView alloc]init];
    view.backgroundColor=Gray_Color;
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, 50)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    MYLabel*orderLabel=[[MYLabel alloc]initWithFrame:CGRectMake(10, 14, MainW-40-size.width, size.height)];
    orderLabel.textColor=TextColor3;
    orderLabel.text=[NSString stringWithFormat:@"%@: %@",MyString(@"订单号"),self.lyModel.orderSn];
    [view1 addSubview:orderLabel];
    MYLabel *statuelabel=[[MYLabel alloc]initWithFrame:CGRectMake(MainW-size.width-15, 14, size.width+5, size.height)];
    statuelabel.textColor=Red_Color;
    statuelabel.text=MyString(@"等待付款");
    statuelabel.textAlignment=NSTextAlignmentRight;
    [view1 addSubview:statuelabel];
    UILabel *timeLable=[[UILabel alloc]initWithFrame:CGRectMake(0, statuelabel.bsg_bottom+9, MainW-10, 15)];
    timeLable.textAlignment=NSTextAlignmentRight;
    timeLable.font=[UIFont systemFontOfSize:11];
    timeLable.textColor=TextColor6;
    timeLable.hidden=YES;
    timeLable.text=@"30分钟后自动关闭";
    [view1 addSubview:timeLable];
    UIView *view3=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bsg_bottom+1, MainW, 50)];
    view3.backgroundColor=[UIColor whiteColor];
    [view addSubview:view3];
    MYLabel*label=[[MYLabel alloc]initWithFrame:CGRectMake(10, 0, MainW-10, 50)];
    label.textColor=TextColor3;
    label.text=[NSString stringWithFormat:@"%@:%@",MyString(@"取消原因"),@"支付宝余额不足"];
    view3.hidden=YES;
    [view3 addSubview:label];
    
    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bsg_bottom+10, MainW, 60)];
    view2.backgroundColor=[UIColor whiteColor];
    [view addSubview:view2];
    UIImageView *icon=[[UIImageView alloc]initWithFrame:CGRectMake(7, 20, 20, 20)];
    icon.image=[UIImage imageNamed:@"deal_location"];
    [view2 addSubview:icon];
    
    UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(37, 10, MainW-180, 15)];
    nameLabel.text=[NSString stringWithFormat:@"%@: %@",MyString(@"收货人"),self.lyModel.buyerAddress.consigneeName];
    nameLabel.textColor=TextColor3;
    nameLabel.font=FontAndStyle12;
    [view2 addSubview:nameLabel];
    UILabel *numLabel=[[UILabel alloc]initWithFrame:CGRectMake(MainW-150, 10, 140, 15)];
    numLabel.text=[NSString stringWithFormat:@"+86 %@",self.lyModel.buyerAddress.consigneePhone];
    numLabel.textColor=TextColor3;
    numLabel.textAlignment=NSTextAlignmentRight;
    numLabel.font=FontAndStyle12;
    [view2 addSubview:numLabel];
    UILabel *addresLabel=[[UILabel alloc]initWithFrame:CGRectMake(37, nameLabel.bsg_bottom+10, MainW-47, 15)];
    addresLabel.text=[NSString stringWithFormat:@"%@: %@%@",MyString(@"收货地址"),self.lyModel.buyerAddress.area,self.lyModel.buyerAddress.detail];
    addresLabel.textColor=TextColor3;
    addresLabel.textAlignment=NSTextAlignmentLeft;
    addresLabel.font=FontAndStyle12;
    [view2 addSubview:addresLabel];
    switch ([self.lyModel.status intValue]) {
        case 10:
        {
            view1.frame=CGRectMake(0, 0, MainW, 60);
            view2.frame=CGRectMake(0, view1.bsg_bottom+10, MainW, 60);
            timeLable.hidden=NO;
            NSDateFormatter * df = [[NSDateFormatter alloc] init];
            df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
            
//            NSString * dateString1 = @"2016-03-23 09:00";
//            NSString * dateString2 = @"2016-03-25 11:00";
            
            NSDate * date1 = [df dateFromString:[self timeWithTimeIntervalString:self.lyModel.closeTime]];
            NSDate * date2 = [df dateFromString:[self getCurrentTime]];
            
            
            NSTimeInterval time = [date1 timeIntervalSinceDate:date2]; //date1是前一个时间(早)，date2是后一个时间(晚)
            int lasttime=(int)time;
            __block int timeout=lasttime; //倒计时时间
            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
            dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
            dispatch_source_set_event_handler(_timer, ^{
                if(timeout <= 0)
                { //倒计时结束，关闭
                    dispatch_source_cancel(_timer);
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        [self.navigationController popViewControllerAnimated:YES];
                    });
                }
                else
                {
                    int seconds = timeout;
                    NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        //self.phoneWord.enabled=NO;
                        timeLable.text=[NSString stringWithFormat:@"%@秒后自动关闭",strTime];
                    });
                    timeout--;
                }
            });
            dispatch_resume(_timer);
            
            //NSLog(@"time = %f", time);
            statuelabel.text=MyString(@"待付款");
        }
            break;
        case 11:
        {
            statuelabel.text=MyString(@"待付定金");
        }
            break;
        case 50:
        {
            statuelabel.text=MyString(@"待付尾款");
        }
            break;
        case 35:
        {
            statuelabel.text=MyString(@"待接单");
        }
            break;
        case 40:
        {
            statuelabel.text=MyString(@"待到店");
        }
            break;
        case 80:
        {
            statuelabel.text=MyString(@"待发货");
        }
            break;
        case 90:
        {
            statuelabel.text=MyString(@"待收货");
        }
            break;
        case 200:
        {
            statuelabel.text=MyString(@"已完成");
        }
            break;
        case 300:
        {
            statuelabel.text=MyString(@"交易取消");
            view3.hidden=NO;
            label.text=[NSString stringWithFormat:@"%@:%@",MyString(@"取消的原因"),self.lyModel.reason];
            view2.frame=CGRectMake(0, view3.bsg_bottom+10, MainW, 60);
        }
            break;
        default:
            break;
    }

    return view;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    itemsModel*model=self.lyModel.items[indexPath.row];
    ShopDetailViewController *vc=[[ShopDetailViewController alloc]init];
    vc.spuId=model.skuId;
    [self.navigationController pushViewController:vc animated:YES];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[[UIView alloc]init];
    view.backgroundColor=Gray_Color;
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 10, MainW, 105)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    MYLabel *totlePrice=[[MYLabel alloc]initWithFrame:CGRectMake(10, 8, MainW/2-10, 15)];
    totlePrice.textColor=TextColor3;
    totlePrice.text=MyString(@"商品总额");
    [view1 addSubview:totlePrice];
    MYLabel *transport=[[MYLabel alloc]initWithFrame:CGRectMake(10, totlePrice.bsg_bottom+6, MainW/2-10, 15)];
    transport.textColor=TextColor3;
    transport.text=MyString(@"运费");
    [view1 addSubview:transport];
    
    MYLabel *Prince=[[MYLabel alloc]initWithFrame:CGRectMake(MainW/2, 8, MainW/2-10, 15)];
    Prince.textColor=Red_Color;
    Prince.text=[NSString stringWithFormat:@"¥ %@",self.lyModel.price];
    Prince.textAlignment=NSTextAlignmentRight;
    [view1 addSubview:Prince];
    MYLabel *transportPrice=[[MYLabel alloc]initWithFrame:CGRectMake(MainW/2, Prince.bsg_bottom+6, MainW/2-10, 15)];
    transportPrice.textColor=Red_Color;
    transportPrice.text=[NSString stringWithFormat:@"¥ %@",self.lyModel.postFee];;
    transportPrice.textAlignment=NSTextAlignmentRight;
    [view1 addSubview:transportPrice];
    UIView *line=[ZJUITools getCutLine];
    line.frame=CGRectMake(10, 53, MainW-20, 0.5);
    [view1 addSubview:line];
    MYLabel *PayPrice=[[MYLabel alloc]init];
    PayPrice.textColor=Red_Color;
    PayPrice.text=[NSString stringWithFormat:@"¥ %@",self.lyModel.price];
    PayPrice.font=[UIFont systemFontOfSize:15];
    PayPrice.textAlignment=NSTextAlignmentRight;
    [view1 addSubview:PayPrice];
    CGSize size=[PayPrice.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    PayPrice.frame=CGRectMake(MainW-10-size.width, line.bsg_bottom+10, size.width, 15);
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, MainW-10-size.width-5, 13)];
    lable.bsg_bottom=PayPrice.bsg_bottom;
    lable.textColor=Red_Color;
    lable.textAlignment=NSTextAlignmentRight;
    lable.font=FontAndStyle12;
    lable.text=MyString(@"需付款");
    [view1 addSubview:lable];
    
    UILabel *tmlable=[[UILabel alloc]initWithFrame:CGRectMake(0, lable.bsg_bottom+6, MainW-10, 15)];
    tmlable.textColor=TextColor6;
    tmlable.textAlignment=NSTextAlignmentRight;
    tmlable.font=FontAndStyle12;
    tmlable.text=[NSString stringWithFormat:@"%@:%@",MyString(@"创建时间"),[self timeWithTimeIntervalString:self.lyModel.createdTime]];
    [view1 addSubview:tmlable];
    
    
    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bsg_bottom+10, MainW, 49)];
    view2.backgroundColor=[UIColor whiteColor];
    [view addSubview:view2];
    //第一个按钮
        UIButton *btn=[[UIButton alloc]init];
        [btn setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        [btn setTitleColor:tableBarRedColor forState:UIControlStateNormal];
        btn.layer.borderWidth=0.5;
        btn.layer.borderColor=tableBarRedColor.CGColor;
        ViewRadius(btn, 2);
        btn.tag=0;
        btn.titleLabel.font=FontAndStyle12;
        btn.frame=CGRectMake(MainW-67, 15, 60, 20);
        [btn addTarget:self action:@selector(orderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:btn];
    //第二个按钮
    UIButton *btn1=[[UIButton alloc]init];
    [btn1 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
    [btn1 setTitleColor:tableBarRedColor forState:UIControlStateNormal];
    btn1.layer.borderWidth=0.5;
    btn1.layer.borderColor=tableBarRedColor.CGColor;
    ViewRadius(btn1, 2);
    btn1.tag=1;
    btn1.titleLabel.font=FontAndStyle12;
    btn1.frame=CGRectMake(MainW-67-65, 15, 60, 20);
    [btn1 addTarget:self action:@selector(orderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:btn1];
    //第三个按钮
    UIButton *btn2=[[UIButton alloc]init];
    [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
    [btn2 setTitleColor:tableBarRedColor forState:UIControlStateNormal];
    btn2.layer.borderWidth=0.5;
    btn2.layer.borderColor=tableBarRedColor.CGColor;
    ViewRadius(btn2, 2);
    btn2.tag=2;
    btn2.titleLabel.font=FontAndStyle12;
    btn2.frame=CGRectMake(MainW-67-130, 15, 60, 20);
    [btn2 addTarget:self action:@selector(orderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:btn2];
    
    //第三个按钮
    UIButton *btn3=[[UIButton alloc]init];
    [btn3 setTitle:MyString(@"删除订单") forState:UIControlStateNormal];
    [btn3 setTitleColor:tableBarRedColor forState:UIControlStateNormal];
    btn3.layer.borderWidth=0.5;
    btn3.layer.borderColor=tableBarRedColor.CGColor;
    ViewRadius(btn3, 2);
    btn3.tag=3;
    btn3.hidden=YES;
    btn3.titleLabel.font=FontAndStyle12;
    btn3.frame=CGRectMake(MainW-67-195, 15, 60, 20);
    [btn3 addTarget:self action:@selector(orderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:btn3];
    
    switch ([self.lyModel.status intValue]) {
        case 10:
        {
             [btn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
             [btn1 setTitle:MyString(@"取消订单") forState:UIControlStateNormal];
             [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        }
            break;
        case 35:
        {
            btn2.hidden=YES;
            [btn setTitle:MyString(@"取消订单") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        }
            break;
        case 40:
        {
            [btn setTitle:MyString(@"已到店") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"取消订单") forState:UIControlStateNormal];
            [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        }
            break;
        case 11:
        {
            [btn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"取消订单") forState:UIControlStateNormal];
            [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        }
            break;
        case 50:
        {
            [btn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"取消订单") forState:UIControlStateNormal];
            [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
        }
            break;
        case 80:
        {
            [btn setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
            btn1.hidden=YES;
            btn2.hidden=YES;
        }
            break;
        case 90:
        {
            [btn setTitle:MyString(@"查看物流") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"确认收货") forState:UIControlStateNormal];
            btn2.hidden=YES;;
        }
            break;
        case 200:
        {
            [btn setTitle:MyString(@"申请售后") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"再次购买") forState:UIControlStateNormal];
            [btn2 setTitle:MyString(@"联系客服") forState:UIControlStateNormal];
            btn3.hidden=NO;
            [btn3 setTitleColor:TextColor6 forState:UIControlStateNormal];
            btn3.layer.borderWidth=0.5;
            btn3.layer.borderColor=TextColor6.CGColor;
        }
            break;
        case 300:
        {
            [btn setTitle:MyString(@"再次购买") forState:UIControlStateNormal];
            [btn1 setTitle:MyString(@"删除订单") forState:UIControlStateNormal];
            [btn1 setTitleColor:TextColor6 forState:UIControlStateNormal];
            btn1.layer.borderWidth=0.5;
            btn1.layer.borderColor=TextColor6.CGColor;
            ViewRadius(btn1, 2);
            btn2.hidden=YES;
        }
            break;
        default:
            break;
    }
    
    return view;
}
-(void)orderBtnClick:(UIButton *)sender{
    switch (sender.tag) {
        case 0:
        {
            switch ([self.lyModel.status intValue]) {
                case 10:
                {
                    [self loadMergeRequest:self.lyModel.orderSn];
                    
                    //NSLog(@"确认付款");
                }
                    break;
                case 11:
                {
                    [self loadMergeRequest:self.lyModel.orderSn];
                    
                    //NSLog(@"确认定金");
                }
                    break;
                case 50:
                {
                    [self loadMergeRequest:self.lyModel.orderSn];
                    
                    //NSLog(@"确认尾款");
                }
                    break;
                case 35:
                {
                    [self cancleClick];
                    
                    //NSLog(@"取消订单");
                }
                    break;
                case 40:
                {
                    [self loadMergeRequest:self.lyModel.orderSn];
                    
                    //NSLog(@"确认到店");
                }
                    break;
                case 80:
                {
                    EaseMessageViewController*vc=[[EaseMessageViewController alloc]initWithConversationChatter:[NSString stringWithFormat:@"%@",self.lyModel.sellerId] conversationType:EMConversationTypeChat];
                    vc.title=[NSString stringWithFormat:@"%@",self.lyModel.sellerId];
                    [self.navigationController pushViewController:vc animated:YES];
                    //[self ContactCustomerService:];
                   //NSLog(@"联系客服");
                }
                    break;
                case 90:
                {
                    LogisticsViewController*vc=[[LogisticsViewController alloc]init];
                    vc.logisticCode=[NSString stringWithFormat:@"%@",self.lyModel.sellerLogistic.logisticCode];
                    vc.orderSn=[NSString stringWithFormat:@"%@",self.lyModel.orderSn];
                    vc.shipperCode=[NSString stringWithFormat:@"%@",self.lyModel.sellerLogistic.shipperCode];
                    vc.shipperName=[NSString stringWithFormat:@"%@",self.lyModel.sellerLogistic.shipperName];
                    
                    vc.imgUrl=[NSString stringWithFormat:@"%@",[self.lyModel.items firstObject].imageUrl];
                    [self.navigationController pushViewController:vc animated:YES];
                    //NSLog(@"查看物流");
                }
                    break;
                case 200:
                {
                    UserOrderModle*modle=[UserOrderModle new];
                    modle.createdTime=self.lyModel.createdTime;
                    modle.orderSn=[NSString stringWithFormat:@"%@",self.lyModel.orderSn];
                    SalesViewController*vc=[[SalesViewController alloc]init];
                    vc.modle=modle;
                    [self.navigationController pushViewController:vc animated:YES];
                    //NSLog(@"申请售后");
                }
                    break;
                case 300:
                {
                    [self buyAgain:self.lyModel.items];
                    //NSLog(@"再次购买");
                }
                    break;
                default:
                    break;
            }

        }
            break;
        case 1:
        {
            switch ([self.lyModel.status intValue]) {
                case 10:
                {
                    //取消订单
                    [self cancleClick];
                }
                    break;
                case 80:
                {
                    //NSLog(@"取消订单");
                }
                    break;
                case 90:
                {
                    [self loadreceiveShop:self.lyModel.orderSn];
                    //NSLog(@"确认收货");
                }
                    break;
                case 200:
                {
                    //NSLog(@"再次购买");
                    [self buyAgain:self.lyModel.items];
                }
                    break;
                case 300:
                {
                    LXAlertView *alert=[[LXAlertView alloc]initWithTitle:MyString(@"提示!") message:MyString(@"订单删除") cancelBtnTitle:MyString(@"取消") otherBtnTitle:MyString(@"确定") clickIndexBlock:^(NSInteger clickIndex) {
                        if (clickIndex==1) {
                           [self deleteOrder:self.lyModel.orderSn];
                        }
                    }];
                    [alert showLXAlertView];
                }
                    break;
                default:
                    break;
            }

        }
            break;

        case 2:
        {
            switch ([self.lyModel.status intValue]) {
                case 10:
                {
                    EaseMessageViewController*vc=[[EaseMessageViewController alloc]initWithConversationChatter:[NSString stringWithFormat:@"%@",self.lyModel.sellerId] conversationType:EMConversationTypeChat];
                    vc.title=[NSString stringWithFormat:@"%@",self.lyModel.sellerId];
                    [self.navigationController pushViewController:vc animated:YES];
                    //NSLog(@"联系客服");
                }
                    break;
                case 5:
                {
                    
                }
                    break;
                case 7:
                {
                    
                }
                    break;
                case 200:
                {
                    EaseMessageViewController*vc=[[EaseMessageViewController alloc]initWithConversationChatter:[NSString stringWithFormat:@"%@",self.lyModel.sellerId] conversationType:EMConversationTypeChat];
                    vc.title=[NSString stringWithFormat:@"%@",self.lyModel.sellerId];
                    [self.navigationController pushViewController:vc animated:YES];
                    //NSLog(@"联系客服");
                }
                    break;
                default:
                    break;
            }

        }
            break;
        case 3:
        {
            LXAlertView *alert=[[LXAlertView alloc]initWithTitle:MyString(@"提示!") message:MyString(@"订单删除") cancelBtnTitle:MyString(@"取消") otherBtnTitle:MyString(@"确定") clickIndexBlock:^(NSInteger clickIndex) {
                if (clickIndex==1) {
                [self deleteOrder:self.lyModel.orderSn];
                    //NSLog(@"删除订单");
                }
            }];
            [alert showLXAlertView];
        }
            break;
            
        default:
            break;
    }
}
//合并支付
-(void)loadMergeRequest:(NSString*)ordersn{
    
    NSArray *array=@[ordersn];
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    //dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orders"]=[array mj_JSONString];
    [self doHttpRequestWithApi:BATCHPAY method:GET dic:dic successBlock:^(NSDictionary *dic) {
        PayViewController *vc=[[PayViewController alloc]init];
         vc.orderDic=[dic[@"data"] copy];
         vc.orderSn=dic[@"data"][@"payNo"];;
         [self.navigationController pushViewController:vc animated:YES];
    }];
}
-(void)buyAgain:(NSArray *)array{
    NSMutableDictionary *dicc=[NSMutableDictionary dictionary];
    NSMutableArray *Array=[NSMutableArray array];
    for (itemsModel*model in array) {
        [dicc setObject:model.quantity forKey:@"number"];
        [dicc setObject:model.skuId forKey:@"skuId"];
        [Array addObject:dicc];
    }
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"carts"]=[Array mj_JSONString];
    [self doHttpRequestWithApi:API_BUYAGAIN method:GET dic:dic successBlock:^(NSDictionary *dic) {
        [MBProgressHUD showSuccess:MyString(@"加入购物车")];
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            MianTabBarViewController *tabbar = [[MianTabBarViewController alloc] init];
//            [tabbar setSelectedIndex:2];
//            [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
//        });
    }];
}
-(void)deleteOrder:(NSString *)ordersn{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=ordersn;
    [self doHttpRequestWithApi:API_REMOVEORDER method:POST dic:dic successBlock:^(NSDictionary *dic) {
        [MBProgressHUD showSuccess:MyString(@"删除成功")];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:YES];
        });
}];
}
//确认收货
-(void)loadreceiveShop:(NSString *)orderSn{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=orderSn;
    [self doHttpRequestWithApi:API_RECEIVESHOP method:POST dic:dic successBlock:^(NSDictionary *dic) {
        //[self.tableView reloadData];
        [MBProgressHUD showSuccess:MyString(@"收货成功")];
        [self dismissDialog];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:YES];
        });
    }];
}
-(NSString*)changeTime:(NSString *)string{
    NSString *str=string;//时间戳
    NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    //NSLog(@"date:%@",[detaildate description]);
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    return currentDateStr;
}
- (NSString *)getCurrentTime {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateTime = [formatter stringFromDate:[NSDate date]];
    return dateTime;
}
-(void)ContactCustomerService:(NSString *)string{
    
}
-(void)cancleClick{
    CancleVC* transparentView = [[CancleVC alloc] init];
    transparentView.orderSn=self.lyModel.orderSn;
    transparentView.cancleBlock = ^(){
		[self showShadow];
        [self showToast:MyString(@"订单取消")];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
			[self disShadow];
            [self.navigationController popViewControllerAnimated:YES];
        });
		
    };
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        transparentView.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }else{
        self.modalPresentationStyle=UIModalPresentationCurrentContext;
    }
    
    transparentView.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.01];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self.navigationController presentViewController:transparentView animated:YES completion:^{///弹出控制器
        ///控制器出现后调用
    }];
//	[self.navigationController pushViewController:transparentView animated:YES];
    //NSLog(@"取消订单");
}
-(void)getDetaiData{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=self.orderSn;
    [self doHttpRequestWithApi:API_ORDERDETAIL_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
        self.lyModel=[LYDetailsModel mj_objectWithKeyValues:dic[@"data"]];
        sellerModel*model=self.lyModel.sellerLogistic;
        buyerAddressModel*model1=self.lyModel.buyerAddress;
        NSLog(@"----%@-----%@",model.logisticCode,model1.area);
        [self.tableView reloadData];
        
    }];
}

@end
